/**
 * @Author: leibidong
 * @Description:商品库存管理
 * @File:  warehouseProductHandler
 * @Version: 1.0.0
 * @Date: 2021/7/6 19:00
 */

package handler

import (
	"ginProject/biz/service"
	"ginProject/biz/utils"
	"ginProject/biz/vo"
	"github.com/gin-gonic/gin"
)

/**
 * @Author leibidong
 * @Description 根据商品id查询商品库存，如果id为空，就查询所有的商品库存
 * @Date  2021/7/6 19:02
 **/
func SelectWarehouseProduct(c *gin.Context) {
	id := c.Query("productId")
	p := service.SelectWarehouseProduct(utils.StringToInt(id))
	if len(p) != 0 {
		utils.ReturnOKMessage(p, c)
	} else {
		utils.ReturnFailureMessage(nil, c)
	}
}

/**
 * @Author leibidong
 * @Description 添加库存信息
 * @Date  2021/7/6 19:52
 **/
func AddWarehouseProduct(c *gin.Context) {
	var addWareHouse vo.AddWareHouse
	c.ShouldBind(&addWareHouse)
	p := service.AddWarehouseProduct(addWareHouse)
	if p != 0 {
		utils.ReturnOKMessage("ok", c)
	} else {
		utils.ReturnFailureMessage(nil, c)
	}
}

/**
 * @Author leibidong
 * @Description 根据库存id更新库存信息
 * @Date  2021/7/6 21:05
 **/
func UpdateWarehouseProduct(c *gin.Context) {
	var updateWare vo.UpdateWareHouse
	c.ShouldBind(&updateWare)
	service.UpdateWarehouseCnt(updateWare)
	utils.ReturnOKMessage("ok", c)
}

/**
 * @Author leibidong
 * @Description 根据库存id删除库存对应信息
 * @Date  2021/7/6 21:09
 **/
func DeleteWarehouseProduct(c *gin.Context) {
	id := c.Query("id")
	status := service.DeleteWarehouseProduct(utils.StringToInt(id))
	if status != 0 {
		utils.ReturnOKMessage("ok", c)
	} else {
		utils.ReturnFailureMessage(nil, c)
	}
}
